package com.example.smartcity_poverty.ui.AllService.NumberBook

import android.content.Context
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.example.smartcity_poverty.App.Companion.context
import com.example.smartcity_poverty.logic.Repository
import com.example.smartcity_poverty.logic.model.NumberBook.NBListModel
import com.example.smartcity_poverty.logic.model.NumberBook.NumberBookUserAllModel

/**
 *  created by ikun
 *  ANDROID STUDIO - version 4.0
 *  email: jinkunwei41@gmail.com
 * --------------------------------
 *  数字图书馆ViewModel
 **/
class NumberBookViewModel : ViewModel(){
    // 获取图书馆列表数据
    private val nBook = MutableLiveData<String>()
    val nBookList = ArrayList<NBListModel.RowsBean>()
    val nBookLiveData = Transformations.switchMap(nBook){
        Repository.getNBList(it)
    }
    fun setToken(token: String){
        nBook.value = token
    }

    // 获取图书馆评论
    private val mBookUserAll = MutableLiveData<Int>()
    val mBookList = ArrayList<NumberBookUserAllModel.DataBean>()
    val mBookLiveData = Transformations.switchMap(mBookUserAll){ query ->
        Repository.getNBUserAll(
            context.getSharedPreferences("token", Context.MODE_PRIVATE).getString("token", "").toString(),
            query
        )
    }
    fun setBookId(id: Int){
        mBookUserAll.value = id
    }
}